﻿using System;
using System.Text;
using System.Xml.Xsl;

namespace Rally_Code_Generator
{
    class Program
    {
        static void Main(string[] args)
        {
            // configure arguments
            string source = args[0];
            string destination = args[1];
            string xsltfile = args[2];
            string entitiesDatabase = args[3];

            XsltArgumentList argsList = new XsltArgumentList();
            argsList.AddParam("EntitiesDatabase", "", entitiesDatabase);

            // setup for conversion
            var myXslTrans = new XslCompiledTransform();
            myXslTrans.Load(xsltfile);
            StringBuilder sb = new StringBuilder();
            System.IO.TextWriter destinationtw = new System.IO.StringWriter(sb);

            // convert input file into output file 
            myXslTrans.Transform(source, argsList, destinationtw);
            


            // save file
            try
            {
                 System.IO.File.WriteAllText(destination, sb.ToString().Replace("&gt;",">"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().ToString());
            }
        }
    }
}
